package com.example.softwareconfigurationcoursedesign;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

// 编辑商品
@WebServlet("/editProduct")
public class EditProductServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 从请求参数获取商品信息
        int productId = Integer.parseInt(request.getParameter("productId"));
        String productName = request.getParameter("productName");
        double productPrice = Double.parseDouble(request.getParameter("productPrice"));
        String productTag = request.getParameter("productTag");
        String productDetail = request.getParameter("productDetail");

        // 更新数据库中的商品信息
        ProductService productService = new ProductService();
        productService.editProduct(productId, productName, productPrice, productTag, productDetail);
        System.out.println("修改商品");
//        // 重定向到商品列表页面
//        response.sendRedirect("productList.jsp");
    }
}